package day_2022_9_to_12.Day;

import java.util.Arrays;

/**
 * @author haomin
 * @date 2022/09/06 17:00
 **/
public class Day4_7_Offer61_IsStraight {
    class Solution {
        public boolean isStraight(int[] nums) {
            int sizeZero = 0;
            for(Integer num : nums) if(num == 0) sizeZero++;
            Arrays.sort(nums);
            for(int i = sizeZero; i < nums.length-1;){
                if((nums[i]+1) != nums[i+1]){
                    if(sizeZero == 0) return false;
                    nums[i] +=1;
                    sizeZero--;
                }else i++;
            }
            return true;
        }
    }
    class Solution2 {
        public boolean isStraight(int[] nums) {
            Arrays.sort(nums);
            int sizeZero = 0;
            for(int i = 0; i < nums.length-1; ++i){
                if(nums[i] == 0) sizeZero++;
                else if(nums[i] == nums[i+1]) return false;
            }
            return nums[4] - nums[sizeZero] < 5;
        }
    }
}